package com.java110.mall.goods.api;

import com.alibaba.fastjson.JSONObject;
import com.java110.mall.goods.bmo.assetInventoryProduct.IDeleteAssetInventoryProductBMO;
import com.java110.mall.goods.bmo.assetInventoryProduct.ISaveAssetInventoryProductBMO;
import com.java110.mall.goods.bmo.assetInventoryProduct.IUpdateAssetInventoryProductBMO;
import com.java110.po.assetInventory.AssetInventoryProductPo;
import com.java110.utils.util.Assert;
import com.java110.utils.util.BeanConvertUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping(value = "/assetInventoryProduct")
public class AssetInventoryProductApi {

    @Autowired
    private ISaveAssetInventoryProductBMO saveAssetInventoryProductBMOImpl;
    @Autowired
    private IUpdateAssetInventoryProductBMO updateAssetInventoryProductBMOImpl;
    @Autowired
    private IDeleteAssetInventoryProductBMO deleteAssetInventoryProductBMOImpl;


    /**
     * 微信保存消息模板
     *
     * @param reqJson
     * @return
     * @serviceCode /assetInventoryProduct/saveAssetInventoryProduct
     * @path /app/assetInventoryProduct/saveAssetInventoryProduct
     */
    @RequestMapping(value = "/saveAssetInventoryProduct", method = RequestMethod.POST)
    public ResponseEntity<String> saveAssetInventoryProduct(@RequestBody JSONObject reqJson) {

        Assert.hasKeyAndValue(reqJson, "specName", "请求报文中未包含specName");
        Assert.hasKeyAndValue(reqJson, "productId", "请求报文中未包含productId");
        Assert.hasKeyAndValue(reqJson, "shopId", "请求报文中未包含shopId");


        AssetInventoryProductPo assetInventoryProductPo = BeanConvertUtil.covertBean(reqJson, AssetInventoryProductPo.class);
        return saveAssetInventoryProductBMOImpl.save(assetInventoryProductPo);
    }

    /**
     * 微信修改消息模板
     *
     * @param reqJson
     * @return
     * @serviceCode /assetInventoryProduct/updateAssetInventoryProduct
     * @path /app/assetInventoryProduct/updateAssetInventoryProduct
     */
    @RequestMapping(value = "/updateAssetInventoryProduct", method = RequestMethod.POST)
    public ResponseEntity<String> updateAssetInventoryProduct(@RequestBody JSONObject reqJson) {

        Assert.hasKeyAndValue(reqJson, "specName", "请求报文中未包含specName");
        Assert.hasKeyAndValue(reqJson, "productId", "请求报文中未包含productId");
        Assert.hasKeyAndValue(reqJson, "shopId", "请求报文中未包含shopId");
        Assert.hasKeyAndValue(reqJson, "detailId", "detailId不能为空");


        AssetInventoryProductPo assetInventoryProductPo = BeanConvertUtil.covertBean(reqJson, AssetInventoryProductPo.class);
        return updateAssetInventoryProductBMOImpl.update(assetInventoryProductPo);
    }

    /**
     * 微信删除消息模板
     *
     * @param reqJson
     * @return
     * @serviceCode /assetInventoryProduct/deleteAssetInventoryProduct
     * @path /app/assetInventoryProduct/deleteAssetInventoryProduct
     */
    @RequestMapping(value = "/deleteAssetInventoryProduct", method = RequestMethod.POST)
    public ResponseEntity<String> deleteAssetInventoryProduct(@RequestBody JSONObject reqJson) {
        Assert.hasKeyAndValue(reqJson, "shopId", "小区ID不能为空");

        Assert.hasKeyAndValue(reqJson, "detailId", "detailId不能为空");


        AssetInventoryProductPo assetInventoryProductPo = BeanConvertUtil.covertBean(reqJson, AssetInventoryProductPo.class);
        return deleteAssetInventoryProductBMOImpl.delete(assetInventoryProductPo);
    }


}
